#ifndef QDECLARATIVESPARTICLES_H
#define QDECLARATIVESPARTICLES_H

#include <QtCore/QAbstractAnimation>
#include <QtDeclarative/qdeclarativeitem_p.h>

#include "qdeclarativesparticlepainter.h"

//an animation that just gives a tick
template<class T, void (T::*method)(int)>
class TickAnimationProxy : public QAbstractAnimation
{
public:
    TickAnimationProxy(T *p, QObject *parent = 0) : QAbstractAnimation(parent), m_p(p) {}
    virtual int duration() const { return -1; }
protected:
    virtual void updateCurrentTime(int msec) { (m_p->*method)(msec); }

private:
    T *m_p;
};

//---------------------------------------------------------------------------
class QDeclarativeSParticlesPrivate : public QDeclarativeItemPrivate
{
    Q_DECLARE_PUBLIC(QDeclarativeParticles)
public:
    QDeclarativeSParticlesPrivate()
        :
//          count(1), emissionRate(-1), emissionVariance(0.5), lifeSpan(1000)
//        , lifeSpanDev(1000), fadeInDur(200), fadeOutDur(300)
//        , angle(0), angleDev(0), velocity(0), velocityDev(0), emissionCarry(0.)
//        , addParticleTime(0), addParticleCount(0),
          lastAdvTime(0),
//        , motion(0),
          clock(this)
    {
    }

    ~QDeclarativeSParticlesPrivate()
    {
    }

    void init()
    {
        Q_Q(QDeclarativeSParticles);
        paintItem = new QDeclarativeSParticlesPainter(this, q);
    }

    void tick(int time);
//    void createParticle(int time);
//    void updateOpacity(QDeclarativeParticle &p, int age);

//    QUrl url;
//    QDeclarativePixmap image;
//    int count;
//    int emissionRate;
//    qreal emissionVariance;
//    int lifeSpan;
//    int lifeSpanDev;
//    int fadeInDur;
//    int fadeOutDur;
//    qreal angle;
//    qreal angleDev;
//    qreal velocity;
//    qreal velocityDev;
//    qreal emissionCarry;
//    int addParticleTime;
//    int addParticleCount;
    int lastAdvTime;
//    QDeclarativeParticleMotion *motion;
    QDeclarativeSParticlesPainter *paintItem;


//    QList<QPair<int, int> > bursts;//countLeft, emissionRate pairs
//    QList<QDeclarativeParticle> particles;
    TickAnimationProxy<QDeclarativeSParticlesPrivate, &QDeclarativeSParticlesPrivate::tick> clock;

};

#endif // QDECLARATIVESPARTICLES_H
